home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-12 | 5.4 KB | 171 lines | [TEXT/PJMM] |
- program TSet;
-
- { Tabby NetMail utility to read 'Next Event' file and update Config file. }
- { Written by Pete Johnson }
-
- { Version 1.6 }
- { Last altered May 26,1991 }
-
- { Revision history: }
- { 06/15/89: Added separate unit to read Config file and went to Toolbox file calls }
- { 07/22/89: Cleaned up code. }
- { 11/6/89: Reduced memory demands. }
- { 11/18/89 WaitNextEvent added for MF compatibility }
- { 05/26/91 V 1.6 added SIZE resource & WaitNextEvent calls }
-
- uses
- Globals, HelloTabby, HostFile;
-
- type
- NextTime = packed array[1..4] of char;
- NextTimePtr = ^NextTime;
- NextTimeHdl = ^NextTimePtr;
- HostTime = packed array[1..3] of char;
- HostTimePtr = ^HostTime;
- HostTimeHdl = ^HostTimePtr;
-
- var
- LaunchHour, LaunchMinute, EventRefNum, ConfigRef: integer;
- NextLaunchTime, NowSeconds, logicalEOF, CharsToSend: longint;
- NowDateRec: DateTimeRec;
- TheNextTimeHdl: NextTimeHdl;
- TheHostTimeHdl: HostTimeHdl;
-
- { ------------------------------------------------------ }
-
- function Make2Digits (ConvertFrom: string): integer;
-
- { Converts two-character string into an ASCII value }
-
- var
- Num1, Num2: integer;
-
- begin
- Num1 := ord(ConvertFrom[1]) - ord('0');
- Num2 := ord(ConvertFrom[2]) - ord('0');
- Make2Digits := Num2 + (Num1 * 10)
- end;
-
- { ------------------------------------------------------ }
-
- procedure HandleDialog;
-
- var
- theDialog: DialogPtr;
- ItemHit, itemType, whichItem: integer;
- itemHandle: Handle;
- dispRect: Rect;
- thisButton: ControlHandle;
-
- begin
- InitCursor;
- theDialog := GetNewDialog(1002, nil, POINTER(-1)); {IM I-413}
- SetPort(theDialog);
- FrameDItem(theDialog, Ok);
- DrawDialog(theDialog);
-
- NextLaunch := GetString(500)^^; { Get next launch string from resource }
- getDItem(theDialog, 3, itemType, itemHandle, dispRect);
- SetIText(Handle(itemHandle), NextLaunch);
-
- if StillDown then
- repeat
- until not Button;
-
- repeat
- ModalDialog(nil, ItemHit); {IM I-415}
- ;
- case ItemHit of
-
- 1: { OK button hit -- save resources }
- begin
- getDItem(theDialog, 3, itemType, itemHandle, dispRect);
- GetIText(Handle(itemHandle), NextLaunch);
- RmveResource(Handle(GetResource('STR ', 500)));
- UpdateResFile(CurrentResFile);
- AddResource(Handle(NewString(NextLaunch)), 'STR ', 500, 'Next Launch');
- end;
-
- 2:
- ; { Cancel button hit—do nothing }
-
- otherwise
- ; { do nothing }
-
- end;
- until (ItemHit = 1) or (ItemHit = 2);
-
- DisposDialog(theDialog)
- end;
-
- { ------------------------------------------------------ }
-
- begin
- CurrentResFile := CurResFile;
- if Button then
- HandleDialog { If user is holding down the mouse button, reconfigure and end }
- else
- begin
- HelloTabby; { Find out what's next on the launchpad }
- if MultiFinder then
- IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
- TheNextTimeHdl := NextTimeHdl(NewHandle(sizeOf(NextTime)));
- TheHostTimeHdl := HostTimeHdl(NewHandle(sizeOf(HostTime)));
- ReadConfig;
- if MultiFinder then
- IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
- Err := GetVol(nil, vRefNum); { Get volume ref # for default volume }
- Err := FSOpen(':Next Event', vRefNum, EventRefNum);
- Err := GetEOF(EventRefNum, logicalEOF);
- if (logicalEOF > 0) & (Err = NoErr) then
- begin
- if MultiFinder then
- IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
- CharsToSend := 4;
- Err := FSRead(EventRefNum, CharsToSend, Ptr(TheNextTimeHdl^));
- Err := FSClose(EventRefNum);
-
- LaunchHour := Make2Digits(copy(TheNextTimeHdl^^, 1, 2));
- LaunchMinute := Make2Digits(copy(TheNextTimeHdl^^, 3, 2));
-
- GetDateTime(NowSeconds);
- Secs2Date(NowSeconds, NowDateRec);
-
- with NextLaunchDateRec do
- begin
- year := NowDateRec.year; { Set up the current year for the Config file }
- month := NowDateRec.month; { Set up the current month for the Config file }
- day := NowDateRec.day; { Set up the current day for the Config file }
- hour := LaunchHour; { Set up the next launch hour for the Config file }
- minute := LaunchMinute; { Set up the next launch minute for the Config file }
- second := 0; { Don't care about seconds }
- if (hour < NowDateRec.hour) then { Hour has passed -- set day to tomorrow }
- day := day + 1
- else if (hour = NowDateRec.hour) and (minute <= NowDateRec.minute) then
- day := day + 1; { Same hour, but minute has passed -- set day to tomorrow }
- TheHostTimeHdl^^[1] := char(LaunchHour);
- TheHostTimeHdl^^[2] := char(LaunchMinute);
- TheHostTimeHdl^^[3] := char(0); { Seconds are always zero }
- end; { with NextLaunchDateRec do }
-
- Date2Secs(NextLaunchDateRec, NextLaunchTime);
- Err := FSOpen('Config', vRefNum, ConfigRef);
- Err := SetFPos(ConfigRef, fsFromStart, 224);
- CharsToSend := 3;
- Err := FSWrite(ConfigRef, CharsToSend, Ptr(TheHostTimeHdl^));
- Err := SetFPos(ConfigRef, fsFromStart, 308);
- CharsToSend := 4;
- Err := FSWrite(ConfigRef, CharsToSend, Ptr(@NextLaunchTime));
- Err := FSClose(ConfigRef);
- end;
- Err := FSClose(EventRefNum);
-
- DisposHandle(Handle(TheNextTimeHdl));
- DisposHandle(Handle(TheHostTimeHdl));
- if MultiFinder then
- IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
-
- if NextLaunch <> '' then
- LaunchNextAppl
- end;
- end.